import type { Request, ResponseToolkit } from "@hapi/hapi";
import Hapi from "@hapi/hapi";
import { TempalteList } from "../../model/index";

let route: Hapi.ServerRoute<Hapi.ReqRefDefaults> = {
  path: "/getAllTemList",
  method: "get",
  handler: async (r: any, h: ResponseToolkit) => {
    try {
      const pageSize = 10; //每页显示的数据条数\n' +
      const currentPage = 1; //当前页\n' +
      const templateList: any = await TempalteList.find()
        .populate("details")
        .skip(pageSize * (currentPage - 1))
        .limit(pageSize);
      console.log(TempalteList, "TempalteList");
      return {
        code: 200,
        data: {
          data: templateList,
          total: templateList.length,
        },
        message: "",
      };
    } catch (err: any) {
      console.log(err, "err");
      return err;
    }
  },
  options: {
    plugins: {
      "hapi-swagger": {
        security: [{ apiKey: [] }],
      },
    },
    tags: ["api"],
  },
};
export default route;
